home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cutils.arc / N.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-08-30  |  11.6 KB  |  310 lines

  1.                         TITLE   Windowing Character Device
  2.                         NAME    WINDOW
  3.  
  4. COMMENT %
  5.                 AUTHOR          Jon Wesener
  6.                 DATE            7 / 22 / 85
  7.                 PURPOSE           This will allow me to control the
  8.                                 scrolling regions on the screen when
  9.                                 everyone else is writing to stdout.
  10.                                 (C) Copyright 1985, BEYOND CONTROL Software.
  11.         %
  12.  
  13.  
  14. CODE            SEGMENT BYTE
  15.                 ASSUME  CS:CODE, DS:NOTHING, ES:NOTHING
  16.  
  17. windev:                                 ; Header for Window Device
  18.                 dd      -1
  19.                 dw      1000000000010000B       ; Con in and Con out & special
  20.                 dw      STRATEGY
  21.                 dw      ENTRY
  22.                 db      'WINDOW  '
  23.  
  24. ; ---------------------------------------------------------
  25. ;       Device Data Structures
  26. ESC             EQU     27
  27. CMD             EQU     2       ; function to perform
  28. STATUS          EQU     3       ; function return status
  29. COUNT           EQU     18      ; ptr to read / write count
  30. TRANS           EQU     14      ; more information for each function
  31. MEDIA           EQU     13      ; Media descriptor
  32. rh_ptr          dd      ?       ; pointer to request header
  33. altah           db      0       ; holds special character
  34. row             db      0       ; current row
  35. col             db      0       ; current col
  36. urow            db      0       ; upper left row of window
  37. ucol            db      0       ; upper left col of window
  38. lrow            db      24      ; lower right row of window
  39. lcol            db      79      ; lower right col of window
  40. rowcol          dw      ?       ; current row and column
  41. state           dw      s1      ; offset to escape processing
  42. attpag          label   word
  43. attr            db      7       ; attribute of character
  44. paged           db      0       ; starting on page zero
  45.  
  46. ; ---------------------------------------------------------
  47. ;       Command Jump Tables
  48. cmdtbl:
  49.                 dw      CON$INIT
  50.                 dw      EXIT
  51.                 dw      EXIT
  52.                 dw      CMDERR
  53.                 dw      CMDERR
  54.                 dw      CMDERR
  55.                 dw      EXIT
  56.                 dw      CMDERR
  57.                 dw      CON$WRIT
  58.                 dw      CON$WRIT
  59.                 dw      EXIT
  60.                 dw      EXIT
  61.  
  62. STRATEGY        PROC    FAR
  63.                 mov     word ptr cs:rh_ptr, bx
  64.                 mov     word ptr cs:rh_ptr+2, es
  65.                 ret
  66. STRATEGY        ENDP
  67.  
  68. ENTRY           PROC    FAR
  69.                 push    ax
  70.                 push    bx
  71.                 push    cx
  72.                 push    dx              ; Save all fucking regs
  73.                 push    di
  74.                 push    si
  75.                 push    bp
  76.                 push    ds
  77.                 push    es
  78.  
  79.                 lds     bx, cs:rh_ptr
  80.                 xor     ax, ax          ; use command as a pointer
  81.                 mov     al, ds:[bx].CMD
  82.                 cmp     al, 11          ; we eleven commands
  83.                 ja      cmderr
  84.  
  85.                 mov     cx, ds:[bx].COUNT
  86.                 les     di, dword ptr ds:[bx].TRANS
  87.  
  88.                 shl     ax, 1           ; word addresses
  89.  
  90.                 mov     si, offset cmdtbl
  91.                 add     si, ax
  92.  
  93. ; ---------------------------------------------------------
  94. ;       Set Data Segment For Our Routines
  95.                 push    cs
  96.                 pop     ds
  97.  
  98.                 ASSUME  DS:CODE
  99. ; ---------------------------------------------------------
  100. ;       Call Specific Routine
  101.                 jmp     word ptr [si]
  102.  
  103. ; ---------------------------------------------------------
  104. ;       Specific routine done, Return to DOS
  105.  
  106. bus$exit:       mov     ah, 11b         ; Device done & busy
  107.                 jmp     err1
  108.  
  109. cmderr:         mov     al, 3           ; Unknown Command Error
  110.  
  111. err$exit:       mov     ah, 10000001b   ; Device done and error occurred
  112.                 jmp     err1
  113.  
  114. exit:           mov     ah, 1b          ; Device done and SUCCESSFUL
  115. err1:           lds     bx,cs:rh_ptr    ; get ptr to request header
  116.                 mov     ds:[bx].STATUS, ax
  117.                                         ; Mark operation complete
  118.                 pop     es
  119.                 pop     ds
  120.                 pop     bp
  121.                 pop     si
  122.                 pop     di
  123.                 pop     dx              ; restore same regs
  124.                 pop     cx
  125.                 pop     bx
  126.                 pop     ax
  127.                 ret
  128. ENTRY           ENDP
  129.  
  130. ; ---------------------------------------------------------
  131. ;       Console Write Routine
  132. COMMENT $
  133.        Note:    The following <ESC>APE sequences have the following effects
  134.  
  135.         <ESC> A#        - Sets the Attribute of the written characters.
  136.         <ESC> C####     - Creates a window of following bytes size
  137.                           clears the window and homes the cursor inside it.
  138.         <ESC> E         - Erases the current window.
  139.         <ESC> P#        - Sets the Page of the displayed screen.
  140.         $
  141.  
  142. CON$WRIT        PROC    NEAR
  143.                 jcxz    exit            ; don't want anything
  144.                 push    cx              ; save count
  145.                 mov     ah, 3           ; get current cursor position
  146.                 mov     bh, paged       ; get for our page
  147.                 int     10h             ; get it
  148.                 cmp     dh, urow
  149.                 jb      resetcurs       ; its below the window
  150.                 cmp     dh, lrow
  151.                 ja      resetcurs       ; its above the window
  152.                 cmp     dl, ucol
  153.                 jb      resetcurs       ; its to the left of window
  154.                 cmp     dl, lcol
  155.                 ja      resetcurs       ; its to the right of window
  156. writc1:         mov     rowcol, dx      ; save row
  157.                 pop     cx              ; get count
  158. con$lp:         mov     al, es:[di]     ; get character
  159.                 inc     di              ; point to the next one
  160.                 push    cx
  161.                 push    di
  162.                 push    es
  163.                 call    video           ; output character
  164.                 pop     es
  165.                 pop     di
  166.                 pop     cx
  167.                 loop    con$lp          ; until all are done
  168.                 jmp     exit
  169.  
  170. resetcurs:      mov     dh, urow
  171.                 mov     dl, ucol        ; home cursor
  172.                 mov     bh, paged       ; get current page
  173.                 mov     ax, 200h
  174.                 int     10h             ; change it
  175.                 jmp     writc1
  176. CON$WRIT        ENDP
  177.  
  178. VIDEO           PROC    NEAR
  179.                 mov     si, offset state
  180.                 jmp     word ptr [si]   ; go to proper routine
  181.  
  182. s1:             cmp     al, ESC
  183.                 jnz     s1b
  184.                 mov     word ptr [si], offset s2
  185.                 ret
  186.  
  187. s1b:            call    chrout
  188. s1a:            mov     state, offset s1       ; put us to a low state
  189.                 ret
  190.  
  191. ; ---------------------------------------------------------
  192. ;       Process Escape Sequence
  193. s2:             cmp     al, 'A'         ; change attribute ?
  194.                 jnz     cretwin         ; try create window
  195.                 mov     state, offset chgatt
  196.                 ret
  197. chgatt:         mov     attr, al        ; save new attribute
  198.                 jmp     s1a             ; were out of the sequence
  199.  
  200. ; ---------------------------------------------------------
  201. ;       Create new window
  202.  
  203. cretwin:        cmp     al, 'C'         ; create window ?
  204.                 jnz     erasewin        ; try change page
  205.                 mov     state, offset cret1
  206.                 ret
  207.  
  208. cret1:          mov     urow, al        ; set upper row
  209.                 mov     state, offset cret2
  210.                 ret
  211. cret2:          mov     ucol, al        ; set upper col
  212.                 mov     state, offset cret3
  213.                 ret
  214. cret3:          mov     lrow, al        ; set lower row
  215.                 mov     state, offset cret4
  216.                 ret
  217. cret4:          mov     lcol, al        ; set lower col
  218.                 jmp     s1a             ; we're done.
  219.  
  220. ; ---------------------------------------------------------
  221. ;       Erase window
  222. erasewin:       mov     al, ucol
  223.                 mov     col, al
  224.                 mov     al, urow
  225.                 mov     row, al         ; home the cursor
  226.                 mov     ax, 600h
  227.                 mov     state, offset s1a
  228.                 jmp     cls
  229.  
  230. ; ---------------------------------------------------------
  231. ;       Set new page
  232. chgpage:        cmp     al, 'P'
  233.                 jnz     s1avec          ; invalid sequence, ignore it
  234.                 mov     state, offset newpage
  235.                 ret
  236. newpage:        cmp     al, 4
  237.                 ja      s1a             ; invalid page number
  238.                 mov     paged, al       ; store new page
  239.                 mov     ah, 5
  240.                 int     10h             ; set active page!
  241. s1avec:         jmp     s1a             ; reset escape state
  242. VIDEO           ENDP
  243.  
  244. CHROUT          PROC    NEAR
  245.                 cmp     al, 13          ; Carriage return
  246.                 jnz     trytab
  247.                 mov     al, ucol        ; get left margin
  248.                 mov     col, al         ; for set it
  249.                 jmp     setit
  250.  
  251. trytab:         cmp     al, 9           ; tab
  252.                 jnz     trylf
  253.                 mov     al, col
  254.                 add     al, 8
  255.                 and     al, 0f8h        ; compute new col
  256.                 mov     col, al
  257.                 jmp     bndchk          ; do a bounds check
  258.  
  259. trylf:          cmp     al, 10          ; line feed
  260.                 jz      lf              ; yes
  261.                 cmp     al, 7           ; bell ?
  262.                 jnz     outchr
  263.  
  264. torom:          mov     bx, attpag      ; get attribute and page
  265.                 mov     ah, 14
  266.                 int     10h             ; send it to rom
  267.                 ret
  268.  
  269. outchr:         mov     bx, attpag      ; get attribute and page
  270.                 mov     cx, 1
  271.                 mov     ah, 9
  272.                 int     10h
  273.                 inc     col
  274. bndchk:         mov     al, col
  275.                 cmp     al, lcol        ; hit max col ?
  276.                 jbe     setit
  277.  
  278.                 mov     al, ucol
  279.                 mov     col, al         ; we're wrapping
  280.  
  281. lf:             inc     row             ; let's see how we do
  282.                 mov     al, row
  283.                 cmp     al, lrow
  284.                 jbe     setit
  285.                 mov     al, lrow
  286.                 mov     row, al         ; we form feeded
  287. scrollup:       mov     ax, 601h        ; scroll up 1 line
  288. cls:            mov     ch, urow
  289.                 mov     cl, ucol
  290.                 mov     dh, lrow
  291.                 mov     dl, lcol
  292.                 mov     bh, attr
  293.                 int     10h             ; scroll it up
  294. setit:          mov     dh, row
  295.                 mov     dl, col
  296.                 mov     bh, paged
  297.                 mov     ah, 2
  298.                 int     10h             ; set cursor position
  299.                 ret
  300. CHROUT          ENDP
  301.  
  302. CON$INIT        PROC    NEAR
  303.                 lds     bx, cs:rh_ptr
  304.                 mov     word ptr [bx].TRANS, offset CON$INIT
  305.                 mov     [bx].TRANS+2, cs
  306.                 jmp     exit
  307. CON$INIT        ENDP
  308. CODE            ENDS
  309.                 END
  310.